Re: [SQL] function year!

Поиск
Список
Период
Сортировка
От Herouth Maoz
Тема Re: [SQL] function year!
Дата
Msg-id l03110703b1fda5b259e3@[147.233.159.109]
обсуждение исходный текст
Ответ на function year!  (Jerome Knobl <jknobl@mandanet.ch>)
Список pgsql-sql
At 11:59 +0300 on 17/8/98, Jerome Knobl wrote:


> Hello,
>
> I have a timestamp value, and I'm tring to get only the year, the month
> or the day.
> I'm using the function now() to put some value inside.
>
> I tried the function year(..) (select year(thedate) from mytable;)
>
> but that function are not define! I'm looking for a simple way to get my
> informations?

You want the year, the month, and the day.

So, define a separate function for each interesting part? A bit of a waste,
isn't it? There is a function "date_part()", which accepts two arguments -
one is a text saying which part you want, and one is the data itself.

Note that it is defined on the datetime type. So if you want to use
timestamp, you will have to convert it, like:

  date_part( 'year', datetime( my_timestamp ) )

As usual, I recommend using the type datetime, not timestamp, in your table.

More information about the date_part() function is in the pgbuiltin man page.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



В списке pgsql-sql по дате отправления:

Предыдущее
От: Jerome Knobl
Дата:
Сообщение: How create an index on a timespamp col!
Следующее
От: Herouth Maoz
Дата:
Сообщение: Re: [GENERAL] The use of sequences